package cn.tx.controller;


import cn.tx.model.Grade;
import cn.tx.page.Page;
import cn.tx.service.EmpService;
import cn.tx.service.GradeService;
import cn.tx.util.StringUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping(path = "/emp")
public class EmpController {

    @Autowired
    private EmpService empService;

    /*首页展示*/
    @RequestMapping(path = "/list")
    public ModelAndView list(ModelAndView modelAndView) {
        modelAndView.setViewName("emp/emp_list");
        return modelAndView;
    }


    /*展示列表*/
    @RequestMapping(path = "/getList", method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> getList(
            @RequestParam(value="name",required=false,defaultValue="") String name,
            Page page
    ) {
        Map<String,Object> map = new HashMap<String,Object>();
        Map<String,Object> querymap = new HashMap<String,Object>();
        querymap.put("name","%"+name+"%");
        querymap.put("offset", page.getOffset());
        querymap.put("pageSize", page.getRows());
        map.put("rows",empService.findList(querymap));
        map.put("total",empService.findTotal(querymap));
        return map;
    }

}
